package com.lywz.core.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.lywz.core.util.SpringUtil;

/**
 * 静态注解赋值
 * 
 * @author Lionel pang
 * @since 1.0.0
 * 
 */
public class StaticAutoWireBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware {

    // spring上下文
    private ApplicationContext context;

    // 缓存表
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
            throws BeansException {
        SpringUtil.beanStaticWire(bean.getClass(), context);
        return bean;
    }

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        this.context = context;
    }

}
